
<!---->
<template>
  <div class="shouPiaoYuanCYQRTZ">
    <basic-container>
      <avue-crud
        ref="shouPiaoYuanCYQRTZ"
        :option="option"
        :table-loading="listLoading"
        :data="list"
        :permission="permissionList"
        :search.sync="searchForm"
        :page.sync="page"
        @search-change="handleFilter"
        @selection-change="selectionChange"
        @refresh-change="refreshChange"
        @on-load="refreshChange">
        <template slot-scope="scope" slot="menuRight">
          <el-button type="primary"  size="mini" @click="sendStatusUpdate">下发</el-button>
          <el-button type="primary"  size="mini" @click="multiAudit">批量审批</el-button>
<!--          <el-button type="primary"  size="mini" @click="multiSetReplyPeriod">设置回复期限</el-button>-->
          <!--<el-button type="primary"  size="mini" @click="noticeSwAuStDiffNotice">通知</el-button>-->
<!--          <el-button type="primary"  size="mini" @click="exportData">导出</el-button>-->
          <el-button type="primary"  size="mini" v-permission="permissionList.handleDelete" @click="handleDelete">删除</el-button>

        </template>
        <template slot-scope="scope" slot="lineCodeSearch">
          <el-select v-model="searchForm.lineCode" placeholder="请选择" style="width: 150px" @change="changeLine" clearable>
            <el-option
              v-for="(item,index) in lineCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot-scope="scope" slot="stationCodeSearch">
          <el-select v-model="searchForm.stationCode" placeholder="请选择" style="width: 150px" clearable>
            <el-option
              v-for="(item,index) in stationCodes"
              :key="index"
              :label="item.name"
              :value="item.code">
            </el-option>
          </el-select>
        </template>
        <template slot="search" slot-scope="{row,size}">
            <el-form-item label="差异条件" style="width: 200px" >
              <el-select v-model="searchForm.isDifferenceAmount" placeholder="请选择"  style="width: 200px"  clearable>
                <el-option label="长款" value="1"></el-option>
                <el-option label="短款" value="2"></el-option>
              </el-select>
            </el-form-item>
        </template>
        <template slot="searchMenu" slot-scope="{row,size}">
          <el-button :size="size" @click="()=>{setSearchFiledsEmpty(row);setSearchFiledsEmpty(searchForm);getList()}" icon="el-icon-delete">清空</el-button>
        </template>
        <template slot-scope="scope" slot="menu">
          <el-button type="text" size="small"
                     plain @click="previewEditor(scope.row)">预览</el-button>

          <!-- <el-button type="primary"  hidden="hidden" size="small" @click="handleDownload(scope.row)">下载附件</el-button> -->
          <!--          下发日期加上期限大于当前日期，说明是期限内-->
<!--          <el-button type="text" size="small"-->
<!--                     v-if="'1'==scope.row.auditSate && scope.row.sendTime && Number(scope.row.replyPeriod) &&-->
<!--                     scope.row.sendState=='1' && scope.row.suappStatus=='0' &&-->
<!--                      (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')>=moment())"-->
<!--                     plain @click.stop="openApprove(scope.row,1)">期限内审批</el-button>-->
<!--          <el-button type="text" size="small"-->
<!--                     v-if="'1'==scope.row.auditSate && scope.row.sendTime && Number(scope.row.replyPeriod) &&-->
<!--                     scope.row.sendState=='1' && scope.row.suappStatus=='0' &&-->
<!--                     (moment(scope.row.sendTime).add(scope.row.replyPeriod,'days')<moment())"-->
<!--                     plain @click.stop="openApprove(scope.row,2)">期限外审批</el-button>-->

        </template>
      </avue-crud>

      <prev ref="prev" v-if="dialogVisibleprev"></prev>

      <el-dialog
        title="设置期限"
        :visible.sync="dialogVisibleReplyPeriod"
        width="30%"
      >
        <span>回复期限（天）：</span>
          <el-input-number v-model="param.replyPeriod" controls-position="right" placeholder="请输入回复期限" :min="0" ></el-input-number>
        <span slot="footer" class="dialog-footer">
          <el-button @click="dialogVisibleReplyPeriod = false">取 消</el-button>
          <el-button type="primary" @click="setReplyPeriod()">确 定</el-button>
        </span>
      </el-dialog>

      <el-dialog
        title="审批"
        :visible.sync="dialogVisibleAppealReply"
        width="30%"
      >
        <span>审批意见：</span>
        <el-input type="textarea" v-model="param.appealReply" maxlength="50" placeholder=""></el-input>
        <span slot="footer" class="dialog-footer">
          <el-button type="primary" @click="setAppealReply(11)">通过</el-button>
          <el-button  @click="setAppealReply(12)">加入补款</el-button>
        </span>
      </el-dialog>
      <approve ref="approve" v-if="approveDialogVisible"></approve>
    </basic-container>
  </div>

</template>

<script>
  import {getForm, postForm} from '@/api/gen/gen'
  import {mapGetters} from 'vuex';
  import moment from 'moment';
  import approve from './approve';
  import {
    clearSelect,
    getgetStationCodes,
    getLineCodes, setSearchFiledsEmpty, getStationByCode, getLineAndStationByCode, getReplayPeriod
  } from "../../../../../api/subwayRat/commonCheck";

  import {exportDataToExcel} from "../../../../../api/subwayRat/exportSelf";
  import {
    approveDataSwAuStDiffNotice,
    getOption,
    getSwAuStDiffNoticeList, noticeSwAuStDiffNotice, sendSwAuStDiffNoticeStatusUpdate,
    setSwAuStDiffNoticeReplyPeriod,delObj,
  } from "../../../../../api/subwayRat/conductorDifferences/conductorTicketChaYiShenhe/cheZhanPKCY/chezhanCYQRTZ";
  import {handleDown,handleDownloadZip} from '@/util/util.js';
  import prev from "@/views/stationTiecketManager/xianWngCJXXQR/cheZhanPKCY/cheZhanPKCYQRTZ/otherYunYingZXDLCK/prev.vue";

  export default {
    name: 'shouPiaoYuanCYQRTZ',
    components:{
      prev,
      approve
    },
    data() {
      return {
        dialogVisibleReplyPeriod:false, //设置回复期限
        dialogVisibleAppealReply:false, //申诉回复
        approveDialogVisible:false,//打开审批界面
        isShowDiaEditor:false,
        isShowDiaAdd:false,
        isShowMergeInfo:false,//是否打开合并信息
        isShowReplace:false,//是否展示替换页面
        dialogVisibleprev:false,//预览
        option: {},
        listLoading: true,
        lineCodes:[],
        stationCodes:[],
        selectKeys:[],
        selectKeyVals:[],
        searchForm:{
          lineCode:'9',
          stationCode:''
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 20, // 每页显示多少条,
          isAsc: false// 是否倒序
        },
        param:{
          replyPeriod:"",//回复期限
          appealReply:'',//申诉回复
        },
        list : []
      }
    },
    computed: {
      ...mapGetters(['permissions']),
      permissionList () {
        return {
          handleDelete: this.vaildData(
            this.permissions.sw_au_st_diff_notice_del,
            false
          ),
        };
      }
    },
    watch: {
    },
    created() {
      this.changeLine("9")
      this.option=getOption();
    },
    methods: {
      setSearchFiledsEmpty,
      moment,
      refreshChange() {
        this.getList()
      },
      getList() {
        this.listLoading = true;
        Object.assign(this.searchForm,this.page);
        this.searchForm.combinStatus=0;
        let th=this;
        getSwAuStDiffNoticeList(this.searchForm).then((response)=>{
          th.list = response.data.data;
          th.listLoading = false;
          th.page.total=response.data.total;
        }).catch(e=>{
          console.log(e)
        });

      },

      previewEditor(row){
        this.dialogVisibleprev=true;
        this.$nextTick(()=>{
          this.$refs.prev.dialogVisible=true;
          this.$refs.prev.recallShow(row,this);
        })
      },

      // downFile(row){
      //   if(!row.fileUrl || row.fileUrl==''){
      //     this.$message.warning("没有附件下载！");
      //     return;
      //   }
      //   handleDown(row.fileUrl,"zdkj");
      // },
      handleDownload(row) {
        let pathList = [];
        if (!this.validatenull(row.fileUrl)) {
          pathList.push(row.fileUrl);
        }
        if (pathList.length == 0) {
          this.$message.info("无附件");
          return;
        }
        handleDownloadZip(pathList, "车站票款附件.zip");
      },
      setReplyPeriod(){ //提交设置回复期限
        if(this.selectKeys.length<=0){
            this.$message.warning("请选择要设置的数据！");
            return;
        }
        if(this.param.replyPeriod==null || this.param.replyPeriod=='' || this.param.replyPeriod==undefined){
          this.$message.warning("请填写回复期限！");
          return;
        }
        setSwAuStDiffNoticeReplyPeriod({replyPeriod:this.param.replyPeriod,ids:this.selectKeyVals.join(",")}).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
            this.dialogVisibleReplyPeriod=false;
          }else{
            this.$message.error("操作失败！");
          }
        }).catch(e=>{
          this.$message.error("操作失败！");
        })
      },
      setAppealReply(auditSate){//申诉回复
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要设置的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++) {
          if ("9" != this.selectKeys[i].auditSate) {
            this.$message.warning("勾选数据中存在审批不通过或审批通过数据！");
            return
          }
        }
        if(this.param.appealReply==null || this.param.appealReply=='' || this.param.appealReply==undefined){
          this.$message.warning("请填写内容！");
          return;
        }
        approveDataSwAuStDiffNotice({auditSate:auditSate,appealReply:this.param.appealReply,ids:this.selectKeyVals.join(",")}).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
            this.dialogVisibleAppealReply=false;
          }else{
            this.$message.error("操作失败！");
          }
        }).catch(e=>{
          this.$message.error("操作失败！");
        })
      },
      async sendStatusUpdate(){ //下发
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要设置的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(this.selectKeys[i].appealState!=1 || this.selectKeys[i].auditSate!=1){
            this.$message.warning("请选择未申诉和待审批的数据！");
            return;
          }
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(this.selectKeys[i].sendState==1 ){
            this.$message.warning("请选择未下发的数据！");
            return;
          }
        }
        let messageLSList = [];
        for(let i=0;i<this.selectKeys.length;i++){
          let data = await getLineAndStationByCode({"lineCode":this.selectKeys[i].lineCode, "code":this.selectKeys[i].stationCode});
          messageLSList.push({
            "content":"车站：" + data.data[0].name,
            "lineCode":this.selectKeys[i].lineCode,
            "stationCode":this.selectKeys[i].stationCode
          })
        }
        let p = {
          messageLSList:JSON.stringify(messageLSList),
          title:this.$store.getters.tag.label,
          msgType:"下发",
          type:"chezhanCYQRTZ_001",
          ids : this.selectKeyVals.join(","),
          sendStatus:1
        };
        sendSwAuStDiffNoticeStatusUpdate(p).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
          }else{
            this.$message.error("操作失败！");
          }
        }).catch(e=>{
          this.$message.error("操作失败！");
        })
      },
      openApprove(row,showType){
        if(row.appealState==1 ){
          this.$confirm("车站人员还未确认，是否要审批？", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          }).then(() => {
            this.approveDialogVisible=true;
            this.$nextTick(()=>{
              this.$refs.approve.dialogVisible=true;
              this.$refs.approve.recallShow(row,showType,this);
            })
          });
        }else{
          this.approveDialogVisible=true;
          this.$nextTick(()=>{
            this.$refs.approve.dialogVisible=true;
            this.$refs.approve.recallShow(row,showType,this);
          })
        }
      },
     //操作批量审批按钮
      multiAudit(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要审批的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
	        if(this.selectKeys[i].sendState==0 ){
            this.$message.warning("请选择已下发数据！");
            return;
          }
          if ("9" != this.selectKeys[i].auditSate) {
            this.$message.warning("勾选数据中存在审批状态非部门审核通过的数据！");
            return
          }
        }
        let statusIds = [];
        for(let i=0;i<this.selectKeys.length;i++){
	        if(this.selectKeys[i].appealState==1 ){
            statusIds.push(this.selectKeys[i].appealState);
          }
        }
        if(statusIds.indexOf('1')>-1){//1代表未申诉
            this.$confirm("所选数据有车站人员还未确认，是否要审批？", "提示", {
              confirmButtonText: "确定",
              cancelButtonText: "取消",
              type: "warning",
            }).then(() => {
              this.dialogVisibleAppealReply=true;
            });
        }else{
          this.dialogVisibleAppealReply=true;
        }
      },
      //批量设置回复期限
       multiSetReplyPeriod(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要设置的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
	   if(this.selectKeys[i].sendState==1 ){
            this.$message.warning("请选择未下发数据！");
            return;
          }
        }
	this.dialogVisibleReplyPeriod=true;
      },
      noticeSwAuStDiffNotice(){
        if(this.selectKeys.length<=0){
          this.$message.warning("请选择要通知的数据！");
          return;
        }
        for(let i=0;i<this.selectKeys.length;i++){
          if(this.selectKeys[i].appealState==1 || this.selectKeys[i].auditSate!=3){
            this.$message.warning("请选择未申诉或者申诉审批不通过的数据！");
            return;
          }
        }
        noticeSwAuStDiffNotice({ids:this.selectKeyVals.join(",")}).then(res=>{
          if(res.data.code==0){
            this.$message.success("操作成功！");
            this.getList();
          }else{
            this.$message.error("操作失败！");
          }
        }).catch(e=>{
          this.$message.error("操作失败！");
        })
      },
      selectionChange(list){
        this.selectKeys=list;
        this.selectKeyVals=[];
        for(let i=0;i<list.length;i++){
          this.selectKeyVals.push(list[i].id);
        }
      },
      handleFilter(params, done) {
        Object.assign(this.searchForm,params);
        this.getList()
        done()
      },
      async exportData(){ // 导出
        let p={};
        Object.assign(p,this.searchForm);
        p.pageNo=1;
        p.pageSize=1000000000;
        if(this.selectKeys.length>0){
            let newData = JSON.parse(JSON.stringify(this.selectKeys));
            exportDataToExcel(newData,this.option.column,'车站差异确认通知');
        }else {
          let res=await getSwAuStDiffNoticeList(p);
          let data = res.data.data;
          exportDataToExcel(data,this.option.column,'车站差异确认通知');
        }
      },
      changeLine(v){ //改变线路时
        getgetStationCodes(v).then(res=>{
          this.stationCodes=res;
          this.searchForm.stationCode='';
        })
      },
      //删除 未加入 已加入 都删除
      handleDelete: function () {
        if (this.selectKeys.length === 0) {
          this.$message.error('请选择要删除的数据！');
          return;
        }
        this.$confirm("是否需要删除?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "success"
        }).then(() => {
          delObj({ids: this.selectKeyVals})
            .then(data => {
              if (data.data.code == "0") {
                this.$message.success("删除成功");
              }
              this.getList();
              done();
            })
            .catch(() => {
              loading();
            });
        });
      },
    },
    mounted() {
      getLineCodes().then(res=>{ //获取线路
        this.lineCodes=res;
      });
      getReplayPeriod({}).then(res=>{
        this.param.replyPeriod=res.data.data.ALTER_limit;
      })
    }
  }
</script>
<style lang="scss">
  .huLianWangShouPiaojiDataInput {
    height: 100%;

    &__tree {
      padding-top: 3px;
      padding-right: 20px;
    }

    &__main {
      .el-card__body {
        padding-top: 0;
      }
    }
    .avue-form__group{

    }
  }
</style>
